﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using BCGC.BLL.BusinessObject.UserAccount;
using Jalal.Library.Utility;
using System.Collections.Generic;
using Jalal.Library.Web;
using System.Collections.Specialized;
using BCGC.BLL.BusinessObject;

public partial class Register : PublicBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ExtendedSessionManager.CurrentRegistrationStep = RegistrationStep.Input;
        if (!IsPostBack)
        {
            InitControls();
        }
    }

    private void InitControls()
    {
        fvmUsername.SetInitialMessage("Your password is required to login to your GStriker account.");
    }

    private bool SetUsernameCheckMessage()
    {
        string username = Security.BindStringInput(tbxUsername.Text, SecurityLevel.Three);
        if (!SiteUser.CheckUsernameTaken(username))
        {
            fvmUsername.SetSuccessMessage("Username is available");
            return true;
        }
        else
        {
            fvmUsername.SetFailMessage("Username is not available");
            return false;
        }
    }

    protected void Username_Validate(object sender, ServerValidateEventArgs e)
    {
        e.IsValid = SetUsernameCheckMessage();
    }

    protected void UserNameAvilableCheck(object sender, EventArgs e)
    {
        SetUsernameCheckMessage();
    }

    protected void Register_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            StringDictionary registerInfo = new StringDictionary();

            registerInfo.Add("Username", Security.BindStringInput(tbxUsername.Text, SecurityLevel.Three));
            registerInfo.Add("Password", Security.BindStringInput(tbxPassword.Text, SecurityLevel.Three));
            registerInfo.Add("Email", Security.BindStringInput(tbxEmail.Text, SecurityLevel.Three));
            registerInfo.Add("SecretQuestion", Security.BindStringInput(tbxSecretQuestion.Text, SecurityLevel.Three));
            registerInfo.Add("SecretAnswer", Security.BindStringInput(tbxSecretAnswer.Text, SecurityLevel.Three));

            ExtendedSessionManager.RegistrationInformation = registerInfo;
            ExtendedSessionManager.CurrentRegistrationStep = RegistrationStep.Confirm;

            Response.Redirect(CustomSiteMap.RegistrationConfirmation);
        }
    }
}
